<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<div style="margin-top: 10px;margin-right: 40px">
    <form class="layui-form" action="javascript:;">
        <div class="layui-form-item">
            <label class="layui-form-label">天数</label>
            <div class="layui-input-block">
                <input name="id" hidden="hidden" <#if info?has_content>value="${info.id}"</#if>>
                <input type="text" name="day" lay-verify="required|number" autocomplete="off" placeholder="请输入天数"
                       class="layui-input" <#if info?has_content>value="${info.day}"</#if>>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">奖励金额</label>
            <div class="layui-input-block">
                <input type="text" name="money" lay-verify="required|number" autocomplete="off" placeholder="请输入奖励金额"
                       class="layui-input" <#if info?has_content>value="${info.money}"</#if>>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>

<script src="/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.$;

        //监听提交
        form.on('submit(demo1)', function (data) {
            var day = data.field.day;
            var index = parent.layer.getFrameIndex(window.name);
            var money = data.field.money;
            var id = data.field.id;

            var json = JSON.stringify(data.field);
            $.ajax({
                type: "POST",
                url: "/signIn/add",
                data: json,
                // dataType: "json",
                contentType: "application/json",
                success: function (data) {
                    parent.layer.close(index);
                },
                error: function (data) {
                    try {
                        layer.msg(JSON.parse(data.responseText).message, {icon: 1, time: 1000});
                    }catch (e) {
                        layer.msg("新增失败");
                    }
                }
            });
        });

    });
</script>

</body>
</html>